<?php

/**
 * Project: CrazyPoems
 * Author: Alexandru
 * Date: 20/10/2008
 * File: config.php
 */

// die('<p>Momentan se lucreaza la pagina.</p> <p>Revenim imediat!<br />Echipa CrazyPoems.</p>');

session_start(); 

// Define website root.
$currentDir = dirname(__FILE__);
//define('HOP_DIR', '/home/crazypoems/crazypoems.net/');
define('HOP_DIR', realpath($currentDir.'/..'));
define('EMAIL_RECIEVE_CONTACT', 'atrandafirc@yahoo.com');
define('SHORT_POEM_SIZE', 300);
define('REGISTRATION_DISABLED', false);
define('ANONIMOUS_COMMENTS_DISABLED', true);
define('USER_PHOTO_PATH', HOP_DIR . '/images_members/');
//define('BASE_URL', 'http://www.crazypoems.net/');
define('BASE_URL', '/');
define('MAIL_URL', 'http://'.$_SERVER['HTTP_HOST'].BASE_URL);
define('USE_MOD_REWRITE', true);
define('_MAGIC_QUOTES_GPC_',         get_magic_quotes_gpc());
define('_MYSQL_REAL_ESCAPE_STRING_', function_exists('mysql_real_escape_string'));

define('__PS_BASE_URI__', BASE_URL);
define('_COOKIE_KEY_', 'WyW3ba7zDfzxCDtH0Aaro74zupSNtQDrkBPIq41FRJh5mwWucXcctxCt');
define('_COOKIE_IV_', 'ZVzuRGH2');

// Load cookies!
require(HOP_DIR.'/inc/Cookie.php');
require(HOP_DIR.'/inc/Blowfish.php');
require(HOP_DIR.'/inc/Tools.php');
$cookie = new Cookie('cp');

// Set time zone.
date_default_timezone_set("Europe/Bucharest");

// Set charset.
header ('Content-type: text/html; charset=UTF-8');

// Load smarty.
require(HOP_DIR.'/smarty/libs/Smarty.class.php');

$smarty = new Smarty();

$smarty->template_dir = HOP_DIR . '/templates';
$smarty->compile_dir = HOP_DIR . '/templates_c';
$smarty->cache_dir = HOP_DIR . '/smarty/cache';
$smarty->config_dir = HOP_DIR . '/smarty/configs';

// Debug.
// $smarty->debugging = true;

// Session variables.
$smarty->assign('session_username', $cookie->username);
$smarty->assign('session_fullname', $cookie->fullname);
$smarty->assign('session_email', $cookie->email);
$smarty->assign('session_admin', $cookie->admin);

// Open database.
require(HOP_DIR . '/inc/db.php');

// Set language.
if (isset($_GET['lang']) && strlen($_GET['lang']) > 0) {
  $cookie->lang = $_GET['lang'];
} else {
  if (strlen($cookie->lang)==0) {
    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
      $array = split(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
      $browserLang = substr($array[0],0,2);
      if ($browserLang!='es') {
        $cookie->lang = 'ro';
      } else {
        $cookie->lang = 'es';
      }
    } else {
      $cookie->lang = 'es';
    }
  }
}
define('LANG', $cookie->lang);

// Load language file.
$_LANG = array();
if (file_exists(HOP_DIR . '/lang/'.LANG.'.php'))
  require_once(HOP_DIR . '/lang/'.LANG.'.php');

// Smarty translate function
function smartyTranslate($params, &$smarty)
{
    global $_LANG;
    $key = $params['s'];
    if (isset($_LANG[$key]))
      return $_LANG[$key];
    else
      return $key;
}
$smarty->register_function('l', 'smartyTranslate');

// Translate function directly from php.
function l($str) {
  global $smarty;
  $params = array('s'=>$str);
  return smartyTranslate($params, &$smarty);
}

// Set the full url used by the translation method
define('LANG_URL', Tools::urlWithout('lang'));

?>
